<template>
  <div class="home">
    <!-- Hero Section -->
    <section class="hero">
      <div class="hero-content">
        <h1>专业美容服务</h1>
        <p>为您提供最优质的美容护理体验，让美丽从内而外绽放</p>
        <button class="cta-button" @click="scrollToServices">探索服务</button>
      </div>
      <div class="hero-image">
        <img src="@/assets/face-protect.png" alt="美容沙龙" />
      </div>
    </section>

    <!-- Features Section -->
    <section class="features">
      <div class="container">
        <h2>为什么选择我们</h2>
        <div class="features-grid">
          <div class="feature-card">
            <div class="feature-icon">⭐</div>
            <h3>专业团队</h3>
            <p>拥有多年经验的专业美容师团队，为您提供个性化服务</p>
          </div>
          <div class="feature-card">
            <div class="feature-icon">🔬</div>
            <h3>先进技术</h3>
            <p>采用最新的美容技术和设备，确保最佳效果</p>
          </div>
          <div class="feature-card">
            <div class="feature-icon">🌿</div>
            <h3>天然产品</h3>
            <p>使用纯天然成分的美容产品，安全无刺激</p>
          </div>
        </div>
      </div>
    </section>

    <!-- Services Preview -->
    <section class="services-preview">
      <div class="container">
        <h2>热门美容项目</h2>
        <div class="services-grid">
          <div class="service-card" v-for="service in featuredServices" :key="service.id">
            <img :src="service.image" :alt="service.name" />
            <div class="service-info">
              <h3>{{ service.name }}</h3>
              <p>{{ service.description }}</p>
              <span class="price">{{ service.price }}</span>
            </div>
          </div>
        </div>
        <router-link to="/services" class="view-all-btn">查看所有项目</router-link>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      featuredServices: []
    }
  },
  async mounted() {
    await this.fetchFeaturedServices();
  },
  methods: {
    async fetchFeaturedServices() {
      try {
        const response = await fetch('/salon/project/list', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
          })
        });
        const data = await response.json();
        // 处理POST请求返回的数据格式
        const services = data.data || data.list || data;
        this.featuredServices = services.slice(0, 3).map(service => ({
          id: service.id,
          name: service.name,
          description: service.description,
          price: `¥${service.price}`,
          image: service.imageUrl
        }));
      } catch (error) {
        console.error('获取服务数据失败:', error);
        // 如果接口调用失败，使用默认数据
      }
    },
    scrollToServices() {
      const servicesSection = document.querySelector('.services-preview');
      servicesSection.scrollIntoView({ behavior: 'smooth' });
    }
  }
}
</script>

<style scoped>
.home {
  min-height: 100vh;
}

.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 4rem;
  padding: 4rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.hero-content h1 {
  font-size: 3rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 1rem;
}

.hero-content p {
  font-size: 1.2rem;
  color: #666;
  margin-bottom: 2rem;
}

.cta-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem 2rem;
  border: none;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.cta-button:hover {
  transform: translateY(-2px);
}

.hero-image img {
  width: 100%;
  height: 400px;
  object-fit: cover;
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.features {
  background: #f8f9fa;
  padding: 4rem 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

.features h2,
.services-preview h2 {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 3rem;
  color: #333;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.feature-card {
  background: white;
  padding: 2rem;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}

.feature-card:hover {
  transform: translateY(-5px);
}

.feature-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.feature-card h3 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: #333;
}

.feature-card p {
  color: #666;
  line-height: 1.6;
}

.services-preview {
  padding: 4rem 0;
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin-bottom: 3rem;
}

.service-card {
  background: white;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}

.service-card:hover {
  transform: translateY(-5px);
}

.service-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.service-info {
  padding: 1.5rem;
}

.service-info h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
  color: #333;
}

.service-info p {
  color: #666;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.price {
  font-size: 1.2rem;
  font-weight: 700;
  color: #667eea;
}

.view-all-btn {
  display: block;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem 2rem;
  border-radius: 50px;
  text-decoration: none;
  font-weight: 600;
  margin: 0 auto;
  max-width: 200px;
  transition: transform 0.3s ease;
}

.view-all-btn:hover {
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .hero {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 2rem;
  }
  
  .hero-content h1 {
    font-size: 2rem;
  }
  
  .features-grid,
  .services-grid {
    grid-template-columns: 1fr;
  }
}
</style>